package com.blue.http;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.blue.core.util.JsonUtil;
import com.blue.http.client.HttpInvoker;
import com.blue.http.message.AccessToken;

public class UploadMain
{
	public UploadMain()
	{
	}
	
	public static void main(String[] args) throws Exception
	{
		String url = "http://localhost:8080/token?name=blue&password=blue123";
		String upload = "http://localhost:8080/upload?token=";
		
		HttpInvoker httpInvoker = new HttpInvoker();
		String resp = httpInvoker.get(url);
		System.out.println(resp);
		AccessToken token = JsonUtil.decode(resp, AccessToken.class);
		
		Map<String, Object> map = new HashMap<>();
		map.put("name", "blue");
		map.put("password", "1234567");
		Map<String, File> fileMap = new HashMap<>();
		String file = TestAuthMain.class.getClassLoader().getResource("file/1.jpg").getFile();
		fileMap.put("file", new File(file));
		
		for (int i = 0; i < 10; i++)
		{
			new Thread(() ->
			{
				try
				{
					String result = httpInvoker.upload(upload + token.getToken(), map, fileMap);
					System.out.println(result);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}).start();
		}
		
	}
	
}
